<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>产品生产工序设计</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../css/public.css" media="all">
    <style>
        body {
            margin: 10px;
        }

        .demo-carousel {
            height: 200px;
            line-height: 200px;
            text-align: center;
        }
    </style>
</head>
<body>
<div id="addGx1">
    <div id="addG2" style="display: none;">
        <form class="layui-form">
            <div class="layui-inline">
                <label class="layui-form-label">搜索选择框</label>
                <div class="layui-input-inline">
                    <select name="modules" id="gxTypeVal" lay-verify="required" lay-search="">
                        <option value="">直接选择或搜索选择</option>
                        <option value="1">组装</option>
                        <option value="2">测试</option>
                        <option value="3">包装</option>
                    </select>
                </div>
            </div>
        </form>
        <div class="layui-form-item">
            <div class="layui-input-block" style=" margin-left: 158px;
    margin-top: 42px;">

                <button type="button" id="addGxButton" style="    display: inline-block;
    height: 38px;
    line-height: 38px;
    padding: 0 18px;
    background-color: #009688;
    color: #fff;
    white-space: nowrap;
    text-align: center;
    font-size: 14px;
    border: none;
    border-radius: 2px;
    cursor: pointer;">立即提交
                </button>
            </div>
        </div>

    </div>
</div>
<!--添加模态框-->
<div id="">

    <div id="addSupper" style="display: none;">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend style="    margin-left: 404px;">生产工序设计单</legend>
        </fieldset>

        <form action="" class="layui-form" lay-filter="">
            <div class="layui-form-item">
                <label class="layui-form-label" style="    margin-left: 70px;">产品名称 :</label>
                <div class="layui-input-inline">
                    <input autocomplete="off" readonly="readonly" style="  border: 0px;   width: 307px;"
                           class="layui-input" id="product_name" lay-verify="required" name="product_name"
                           placeholder="" type="text">

                </div>
                <label class="layui-form-label" style="    margin-left: 165px;">产品编号 :</label>
                <div class="layui-input-inline">
                    <input autocomplete="off" readonly="readonly" style="  border: 0px;   width: 307px;"
                           class="layui-input" id="prdouctId" lay-verify="required" name="productId"
                           placeholder="" type="text">

                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" style="    margin-left: 70px;">设计人 :</label>
                <div class="layui-input-inline">
                    <input autocomplete="off" style="border: 0;    width: 307px;" readonly="readonly"
                           class="layui-input" id="designregister"
                           lay-verify="required" name="product_name"
                           type="text">

                </div>
                <input autocomplete="off" style="    width: 307px;" class="layui-input" id="desginregister"
                       lay-verify="required" name="register"
                       placeholder="请输入设计人的名称" type="hidden">

            </div>
            <table class="layui-table" id="test3" lay-filter="test3">

            </table>
            <div class="layui-form-item">
                <label class="layui-form-label" style="    margin-left: 70px;">登记人 :</label>
                <div class="layui-input-inline">
                    <input autocomplete="off" style="    width: 307px;" class="layui-input" id="register"
                           lay-verify="required" name="register"
                           placeholder="请输入登记人的名称" type="text">

                </div>
                <label class="layui-form-label" style="        margin-left: 137px;">登记时间 :</label>
                <div class="layui-input-inline">
                    <input autocomplete="off" style="    width: 307px;" class="layui-input" id="register_time"
                           lay-verify="required" name="register_time"
                           placeholder="" type="text">

                </div>

            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">设计要求</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block" style="    margin-left: 400px;">

                    <input type="hidden" id="gprocuJson" name="gprocuJson">
                    <button type="button" id="addProduction_process_design" class="layui-btn">立即提交</button>
                    <i class="layui-icon" id="addGx"
                       style="display: inline-block;  height: 38px;   line-height: 38px;   padding: 0 18px;   background-color: #009688;  color: #fff;   white-space: nowrap;   text-align: center;  font-size: 14px;   border: none;    border-radius: 2px;   cursor: pointer;">添加工序</i>
                </div>
            </div>
        </form>
    </div>
</div>
<blockquote class="layui-elem-quote news_search" style=" border-left: 0px solid #009688;">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so" id="complain_search">
            建档时间:
            <div class="layui-input-inline">
                <input type="text" name="date" id="date" autocomplete="off" class="layui-input">


            </div>
            至
            <div class="layui-input-inline">
                <input type="text" name="date1" id="date1" autocomplete="off" class="layui-input">


            </div>
            <button id="search" class="layui-btn" lay-submit
                    lay-filter="provinceSearch">
                <i class="layui-icon">&#xe615;</i>
            </button>
        </form>
    </div>
    <table class="layui-hide" id="complainTable" lay-filter="complainList"></table>
</blockquote>

<script type="text/html" id="complain_toolbar">
    <div class="layui-btn-container">
    </div>


</script>
<script type="text/html" id="barDemo2">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">制定设计单</a>
</script>

<script src="../../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="../../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="../../../lib/jq-module/jquery.particleground.min.js" charset="utf-8"></script>
<script src="../../../lib/common/jquery.cookie.min.js" charset="utf-8"></script>
<script src="../../../lib/common/common.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script type="text/javascript">
    layui.use(['table', 'layer', 'form', 'laypage'], function () {
        var table = layui.table,
            layer = layui.layer,
            form = layui.form,
            laypage = layui.laypage;

        var tableIns = table.render({
            id: "provinceReload"
            , elem: '#complainTable'
            , url: 'http://localhost:8008/productions/selectcheckAll'
            , parseData: function (res) {
                console.log(res);
                return {
                    "data": res,
                    "code": 0
                }

            }
            , page: true
            , toolbar: '#complain_toolbar'
            , cols: [[ //表头
                {type: 'checkbox', fixed: 'left'}
                , {field: 'id', title: 'ID', hide: true}
                , {field: 'productId', title: '产品编号', width: 300, sort: true, fixed: 'left', totalRowText: '合计：'}
                , {field: 'productClass', title: '档次级别', width: 380}
                , {field: 'register', title: '设计人', width: 300, sort: true, totalRow: true}
                , {field: 'registerTime', title: '设计时间', width: 420, sort: true}
                , {fixed: 'right', width: 200, align: 'center', toolbar: '#barDemo'}
            ]]
            , limits: [5, 10, 20, 50]
        });

        table.on('toolbar(complainList)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id),
                data = checkStatus.data;
            data = eval("(" + JSON.stringify(data) + ")");
            switch (obj.event) {
                case 'add':
                    break;
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'Supperdeletes':
                    break;
            }
        });
        $("#addProduction_process_design").click(function () {
            var product_name = $("#product_name").val();
            var design_idB = $("#procedure_id").val();
            var product_designer = $("#product_designer").val();
            var product_registrant = $("#register").val();
            var design_date = $("#register_time").val();
            var esign_require = $(".layui-textarea").val();

            var datas = [];

            var delIndex = layer.confirm('确定提交吗', function (delIndex) {
                layui.use('table', function () {
                    var table = layui.table;

                    datas = layui.table.cache["test3"];
                    JSON.stringify(datas);//把JS对象转换为json 这个是获取所有
                    $.ajax({
                        url: 'http://127.0.0.1:8003/process/insertProductionSheet',
                        data: {
                            'product_name': product_name,
                            'design_idB': design_idB,
                            'product_designer': product_designer,
                            'product_registrant': product_registrant,
                            'design_date': design_date,
                            'esign_require': esign_require,
                            'prdouctId':  prdouctId,
                            'gprocuJson1': JSON.stringify(datas)
                        },
                        success: function (data) {
                            layer.msg("提交成功");
                            window.parent.location.reload();//刷新父页面
                            layer.closeAll();
                        }
                    })

                })


            });
        })
        table.on('tool(complainList)', function (obj) {
            var data = obj.data;
            json = JSON.stringify(data);
            switch (obj.event) {
                case 'detail':
                    break;
                case 'edit':
                    console.log(data.productId);
                    $("#product_name").val(data.productName);
                    $("#prdouctId").val(data.productId);
                    $("#designregister").val(data.register);
                    var AddData = [];
                    table.render({
                        elem: '#test3',
                        height: 150
                        , cols: [[
                            {field: 'process_name', width: 120, title: '工序名称',}
                            , {field: 'process_id', width: 120, title: '工序编号'}
                            , {field: 'process_describe', width: 120, title: '工序描述', edit: true,}
                            , {field: 'process_time_gs', width: 120, title: '工时数', edit: true,}
                            , {field: 'process_time_unitdw', title: '工时单位', width: 120, edit: true,}
                            , {field: 'process_time_cost', width: 120, title: '单位工时成本', edit: true}
                            , {field: 'process_subtotal', width: 120, title: '工时成本小计',edit: true}
                            , {fixed: 'right', width: 120, align: 'center', toolbar: '#barDemo2'}

                        ]],
                        data: AddData

                    });


                    layer.open({
                        maxmin: true,
                        type: 1,//类型 信息
                        area: ['1000px', '600px'],//定义宽和高
                        title: '制定设计单',//题目
                        shadeClose: false,//点击遮罩层关闭
                        content: $('#addSupper')//打开的模态框

                    });
                    break;
                case 'del':
                    var delIndex = layer.confirm('真的删除id为' + data.id + "的信息吗?", function (delIndex) {
                        $.ajax({
                            url: 'http://127.0.0.1:8005/supper/delsupperById?id=' + data.id,
                            success: function (suc) {

                                obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                                layer.close(delIndex);
                                console.log(delIndex);
                                layer.msg("删除成功", {
                                    icon: 1
                                });

                            }
                        });
                        layer.close(delIndex);
                    });
                    break;
            }
        });
        //监听提交
        form.on('submit(supperSub)', function (data) {
            var edC = $("#edidId").val();
            if (edC == 1) {
                $.ajax({
                    url: 'http://127.0.0.1:8005/supper/updateSupperById',
                    data: data.field,
                    success: function (data) {
                        layer.msg("提交成功")
                    }
                })
            }
            if (edC != 1) {
                $.ajax({
                    url: 'http://127.0.0.1:8005/supper/insertSupper',
                    data: data.field,
                    success: function (data) {
                        layer.msg("提交成功")
                    }
                })
                return;
            }
            layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            })


        });
        $("#addGx").click(function () {
            layer.open({
                maxmin: true,
                type: 1,//类型 信息
                area: ['400px', '200px'],//定义宽和高
                title: '工序选择',//题目
                shadeClose: false,//点击遮罩层关闭
                content: $('#addG2')//打开的模态框

            });
        })

        form.render();
        form.on('submit(provinceSearch)', function (data) {
            var formData = data.field;
            var serviceCode = formData.serviceCode,
                compOrder = formData.compOrder,
                compType = formData.compType,
                complainState = formData.complainState;
            table.reload('provinceReload', {
                page: {
                    curr: 1
                },

                url: 'http://127.0.0.1:8005/supper/sellName?name=' + formData.name,
            });
            return false;
        });

    });
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });
        laydate.render({
            elem: '#register_time'
        });


        //监听提交
        form.on('submit(demo1)', function (data) {
            layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            })
            return false;
        });

        //表单赋值
        layui.$('#LAY-component-form-setval').on('click', function () {
            form.val('example', {
                "username": "贤心" // "name": "value"
                , "password": "123456"
                , "interest": 1
                , "like[write]": true //复选框选中状态
                , "close": true //开关状态
                , "sex": "女"
                , "desc": "我爱 layui"
            });
        });

        //表单取值
        layui.$('#LAY-component-form-getval').on('click', function () {
            var data = form.val('example');
            alert(JSON.stringify(data));
        });

    });
    layui.use('table', function () {
        var table = layui.table;
        var AddData = [];
        table.on('tool(test3)', function (obj) {
            var data = obj.data;
            //console.log(obj)
            if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    console.log(index)
                    AddData.splice($.inArray(index, AddData), 1);
                    obj.del();
                    layer.close(index);
                });
            }
        });
        $("#addGxButton").click(function () {

            var datas = layui.table.cache["test3"];
            var gxType = $(".layui-input").val();
            var gId = $("#gxTypeVal").val();
            var data1 = {"process_name": gxType, "process_id": gId};
            AddData.unshift(data1);
            console.log(AddData)
            table.reload('test3', {
                data: AddData
            });

        });
        //  form.on('submit(test-submit-add)', function (data) {
        //      table.cache['test3'].push(data.field);
        //     table.reload('test3', { data: table.cache['test3']});


        //    });
        //监听行工具事件

        //监听单元格编辑
        table.on('edit(test3)', function (obj) {
            var value = obj.value //得到修改后的值
                , data = obj.data //得到所在行所有键值
                , field = obj.field; //得到字段
            //   layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value);
        });
    });
</script>


</body>
</html>
